var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send({ id: Date.now(), name: 'coderwhy', token: Date.now().toString() });
});

router.get('/:id', function (req, res, next) {
  console.log('888', req.params);
  res.send({
    code: 0,
    data: {
      id: 1,
      name: 'codeywhy',
      cellphone: '12345678901',
      enable: 1,
      createAt: '2021-01-02 18: 20: 21.000',
      updateAt: '2021-01-02 18: 20: 21.000',
      role: {
        id: 1,
        name: '超级管理员',
        intro: '所有模块',
        createAt: '2021-01-02 18: 20: 21.000',
        updateAt: '2021-01-02 18: 20: 21.000',
      },
      department: {
        id: 1,
        name: '总裁办',
        parentId: null,
        createAt: '2021-01-02 18: 20: 21.000',
        updateAt: '2021-01-02 18: 20: 21.000',
        leader: 'coderwhy',
      },
    },
  });
});

router.get('/role/:id/menu', function (req, res, next) {
  res.send({
    code: 200,
    data: [
      {
        id: 38,
        name: '商品中心',
        type: 1,
        url: '/main/product',
        icon: 'el-icon-monitor',
        children: [
          {
            id: 39,
            name: '商品概况',
            type: 2,
            url: '/main/product/goods',
            icon: 'el-icon-s-data',
          },
        ],
      },
      {
        id: 1,
        name: '系统管理',
        type: 1,
        url: '/main/system',
        icon: 'el-icon-setting',
        children: [
          {
            id: 2,
            name: '用户管理',
            type: 2,
            url: '/main/system/user',
            icon: 'el-icon-user',
          },
          {
            id: 3,
            name: '角色管理',
            type: 2,
            url: '/main/system/role',
            icon: 'el-icon-user-solid',
            children: [
              { id: 31, name: '创建用户', parentId: 3, type: 3, permission: 'system:user:create' },
              { id: 32, name: '编辑用户', parentId: 3, type: 3, permission: 'system:user:update' },
              { id: 33, name: '删除用户', parentId: 3, type: 3, permission: 'system:user:delete' },
            ],
          },
          {
            id: 4,
            name: '菜单管理',
            type: 2,
            url: '/main/system/menu',
            icon: 'el-icon-user-solid',
          },
          {
            id: 5,
            name: '部门管理',
            type: 2,
            url: '/main/system/department',
            icon: 'el-icon-user-solid',
          },
        ],
      },
      {
        id: 9,
        name: '服务中心',
        type: 1,
        url: '/main/story',
        icon: 'el-icon-goods',
        children: [
          {
            id: 10,
            name: '聊天',
            type: 2,
            url: '/main/story/chat',
            icon: 'el-icon-tickets',
          },
          {
            id: 11,
            name: '留言',
            type: 2,
            url: '/main/story/dashboard',
            icon: 'el-icon-folder-opened',
          },
          {
            id: 12,
            name: '列表',
            type: 2,
            url: '/main/story/list',
            icon: 'el-icon-tickets',
          },
          {
            id: 13,
            name: '概览',
            type: 2,
            url: '/main/story/overview',
            icon: 'el-icon-folder-opened',
          },
        ],
      },
    ],
  });
});

/* POST users list */
router.post('/list', function (req, res, next) {
  console.log('🚀 ~ req:', req.body);
  const { offset, size } = req.body;
  const users = [];

  for (let i = offset; i < offset + size; i++) {
    users.push({
      id: i + 1,
      name: `user${i + 1}`,
      realname: `Real Name ${i + 1}`,
      cellphone: `123456789${i + 1}`,
      enable: i % 2 === 0 ? 1 : 0,
      departmentId: Math.floor(Math.random() * 5) + 1,
      roleId: Math.floor(Math.random() * 5) + 1,
      createAt: new Date().toISOString(),
      updateAt: new Date().toISOString(),
    });
  }
  res.send({ code: 0, data: { list: users, total: users.length * 10 } });
});
module.exports = router;
